package o;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import javax.annotation.Nullable;

public abstract class fuy implements Closeable {

    class AnonymousClass1 extends fuy {
        final /* synthetic */ fup ˋ;
        final /* synthetic */ long ˏ;
        final /* synthetic */ fxg ॱ;

        AnonymousClass1(fup o_fup, long j, fxg o_fxg) {
            this.ˋ = o_fup;
            this.ˏ = j;
            this.ॱ = o_fxg;
        }

        @Nullable
        public fup ˊ() {
            return this.ˋ;
        }

        public long ˏ() {
            return this.ˏ;
        }

        public fxg ˋ() {
            return this.ॱ;
        }
    }

    @Nullable
    public abstract fup ˊ();

    public abstract fxg ˋ();

    public abstract long ˏ();

    public final InputStream ˎ() {
        return ˋ().ʽ();
    }

    public final byte[] ॱ() throws IOException {
        long ˏ = ˏ();
        if (ˏ > 2147483647L) {
            throw new IOException("Cannot buffer entire body for content length: " + ˏ);
        }
        Closeable ˋ = ˋ();
        try {
            byte[] ʻॱ = ˋ.ʻॱ();
            if (ˏ == -1 || ˏ == ((long) ʻॱ.length)) {
                return ʻॱ;
            }
            throw new IOException("Content-Length (" + ˏ + ") and stream length (" + ʻॱ.length + ") disagree");
        } finally {
            fvg.ॱ(ˋ);
        }
    }

    public final String ʽ() throws IOException {
        Closeable ˋ = ˋ();
        try {
            String ˏ = ˋ.ˏ(fvg.ˎ(ˋ, ʼ()));
            return ˏ;
        } finally {
            fvg.ॱ(ˋ);
        }
    }

    private Charset ʼ() {
        fup ˊ = ˊ();
        return ˊ != null ? ˊ.ˏ(fvg.ˎ) : fvg.ˎ;
    }

    public void close() {
        fvg.ॱ(ˋ());
    }

    public static fuy ˋ(@Nullable fup o_fup, String str) {
        Charset charset = fvg.ˎ;
        if (o_fup != null) {
            charset = o_fup.ॱ();
            if (charset == null) {
                charset = fvg.ˎ;
                o_fup = fup.ॱ(o_fup + "; charset=utf-8");
            }
        }
        fxg ॱ = new fxi().ॱ(str, charset);
        return ˊ(o_fup, ॱ.ॱ(), ॱ);
    }

    public static fuy ˎ(@Nullable fup o_fup, byte[] bArr) {
        return ˊ(o_fup, (long) bArr.length, new fxi().ˎ(bArr));
    }

    public static fuy ˊ(@Nullable fup o_fup, long j, fxg o_fxg) {
        if (o_fxg != null) {
            return new AnonymousClass1(o_fup, j, o_fxg);
        }
        throw new NullPointerException("source == null");
    }
}
